import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("ListModel动态模型")

    ListModel {
        id: cityModel
        ListElement { name: "北京"; code: "010" }
        ListElement { name: "上海"; code: "021" }
        ListElement { name: "广州"; code: "020" }
    }

    ComboBox {
        anchors.centerIn: parent
        model: cityModel
        textRole: "name"

        onActivated: {
            console.log("选中城市代码:", cityModel.get(currentIndex).code)
        }
    }
}
